<template>
  <el-table
    :data="data"
    ref="JADPTable"
    class="JADP-common-table"
    :height="height"
    :element-loading-text="$t('common.loadingText')"
    v-bind="$attrs"
    v-on="$listeners"
    width="100%"
    :border="border"
  >
    <el-table-column
      type="selection"
      v-if="hasC"
      align="center"
      :selectable="isChecked"
    />
    <el-table-column
      type="index"
      width="50"
      label="序号"
      v-if="hasNO"
      align="center"
    />
    <slot></slot>
    <template slot="empty">
      <el-empty description="暂无数据" :image-size="120"></el-empty>
    </template>
  </el-table>
</template>

<script>
export default {
  name: "JADP-table",
  props: {
    checkList: {},
    data: {
      type: Array, 
      default: () => [],
    },
    noCheck: {
      type: Boolean,
      default: false,
    },
    columnData: {
      type: Array,
      default: () => [],
    },
    // 序号 默认有
    hasNO: {
      type: Boolean,
      default: true,
    },
    // 多选框 默认无
    hasC: {
      type: Boolean,
      default: false,
    },
    border: {
      type: Boolean,
      default: true,
    },
    height: {
      default: "100%",
    },
  },
  data() {
    return {
      checkList_: [],
    };
  },
  watch: {
    data: {
      handler(val) {
        if (!val) return;
        this.doLayout();
      },
      deep: true,
    },
    columnData: {
      handler(val) {
        if (!val) return;
        this.doLayout();
      },
      deep: true,
    },
    checkList: {
      immediate: true,
      handler(val) {
        if (val) {
          this.checkList_ = val.list.map((item) => item.crmid);
        }
      },
    },
  },
  methods: {
    isChecked(row, index) {
      if (!this.noCheck) return true;
      else {
        let c = this.checkList_.includes(row.id);
        if (c) return false;
        return true;
      }
    },
    doLayout() {
      setTimeout(() => {
        this.$nextTick(() => {
          this.$refs.JADPTable.doLayout();
        });
      }, 50);
    },
  },
};
</script>